home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 3.iso / dist / fw_apache.idb / usr / freeware / apache / sbin / apxs.z / apxs
Text File  |  2001-01-10  |  21KB  |  663 lines

  1. #!/usr/bin/perl5
  2. ## ====================================================================
  3. ## Copyright (c) 1998-1999 The Apache Group.  All rights reserved.
  4. ##
  5. ## Redistribution and use in source and binary forms, with or without
  6. ## modification, are permitted provided that the following conditions
  7. ## are met:
  8. ##
  9. ## 1. Redistributions of source code must retain the above copyright
  10. ##    notice, this list of conditions and the following disclaimer. 
  11. ##
  12. ## 2. Redistributions in binary form must reproduce the above copyright
  13. ##    notice, this list of conditions and the following disclaimer in
  14. ##    the documentation and/or other materials provided with the
  15. ##    distribution.
  16. ##
  17. ## 3. All advertising materials mentioning features or use of this
  18. ##    software must display the following acknowledgment:
  19. ##    "This product includes software developed by the Apache Group
  20. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  21. ##
  22. ## 4. The names "Apache Server" and "Apache Group" must not be used to
  23. ##    endorse or promote products derived from this software without
  24. ##    prior written permission. For written permission, please contact
  25. ##    apache@apache.org.
  26. ##
  27. ## 5. Products derived from this software may not be called "Apache"
  28. ##    nor may "Apache" appear in their names without prior written
  29. ##    permission of the Apache Group.
  30. ##
  31. ## 6. Redistributions of any form whatsoever must retain the following
  32. ##    acknowledgment:
  33. ##    "This product includes software developed by the Apache Group
  34. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  35. ##
  36. ## THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  37. ## EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. ## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  40. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  45. ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  47. ## OF THE POSSIBILITY OF SUCH DAMAGE.
  48. ## ====================================================================
  49. ##
  50. ## This software consists of voluntary contributions made by many
  51. ## individuals on behalf of the Apache Group and was originally based
  52. ## on public domain software written at the National Center for
  53. ## Supercomputing Applications, University of Illinois, Urbana-Champaign.
  54. ## For more information on the Apache Group and the Apache HTTP server
  55. ## project, please see <http://www.apache.org/>.
  56. ##
  57.  
  58. ##
  59. ##  apxs -- APache eXtenSion tool
  60. ##  Written by Ralf S. Engelschall <rse@apache.org>
  61. ##
  62.  
  63. require 5.003;
  64. use strict;
  65. package apxs;
  66.  
  67. ##
  68. ##  Configuration
  69. ##
  70.  
  71. my $CFG_ROOT          = $ENV{ROOT};                    # added by SGI Freeware
  72. my $CFG_TARGET        = q(httpd);                    # substituted via Makefile.tmpl
  73. my $CFG_CC            = q(cc);                        # substituted via Makefile.tmpl
  74. my $CFG_CFLAGS        = q( -DIRIX -n32 -DMOD_SSL=207101 -DUSE_HSREGEX -DEAPI -DUSE_EXPAT -I../lib/expat-lite `../apaci`);
  75. my $CFG_CFLAGS_SHLIB  = q(-KPIC -DSHARED_MODULE);            # substituted via Makefile.tmpl
  76. my $CFG_LD_SHLIB      = q(ld);                        # substituted via Makefile.tmpl
  77. my $CFG_LDFLAGS_SHLIB = q(-n32 -shared);                # substituted via Makefile.tmpl
  78. my $CFG_LIBS_SHLIB    = q();                        # substituted via Makefile.tmpl
  79. my $CFG_PREFIX        = qq(${CFG_ROOT}/usr/freeware/apache);        # substituted via APACI install
  80. my $CFG_SBINDIR       = qq(${CFG_ROOT}/usr/freeware/apache/sbin);    # substituted via APACI install
  81. my $CFG_INCLUDEDIR    = qq(${CFG_ROOT}/usr/freeware/apache/include);    # substituted via APACI install
  82. my $CFG_LIBEXECDIR    = qq(${CFG_ROOT}/usr/freeware/apache/libexec);    # substituted via APACI install
  83. my $CFG_SYSCONFDIR    = qq(${CFG_ROOT}/usr/freeware/apache/etc);    # substituted via APACI install
  84.  
  85. ##
  86. ##  Cleanup the above stuff
  87. ##
  88. $CFG_CFLAGS =~ s|^\s+||;
  89. $CFG_CFLAGS =~ s|\s+$||;
  90. $CFG_CFLAGS =~ s|\s+`.+apaci`||;
  91.  
  92. ##
  93. ##  parse argument line
  94. ##
  95.  
  96. #   defaults for parameters
  97. my $opt_n = '';
  98. my $opt_g = '';
  99. my $opt_c = 0;
  100. my $opt_o = '';
  101. my @opt_D = ();
  102. my @opt_I = ();
  103. my @opt_L = ();
  104. my @opt_l = ();
  105. my @opt_W = ();
  106. my @opt_S = ();
  107. my $opt_e = 0;
  108. my $opt_i = 0;
  109. my $opt_a = 0;
  110. my $opt_A = 0;
  111. my $opt_q = 0;
  112.  
  113. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  114. #   the "+" metacharater at the format string to allow a list to be build by
  115. #   subsequent occurance of the same option.
  116. sub Getopts {
  117.     my ($argumentative, @ARGV) = @_;
  118.     my (@args, $first, $rest, $pos);
  119.     my ($errs) = 0;
  120.     local ($_);
  121.     local ($[) = 0;
  122.  
  123.     @args = split( / */, $argumentative);
  124.     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  125.         ($first, $rest) = ($1,$2);
  126.         if ($_ =~ m|^--$|) {
  127.             shift(@ARGV);
  128.             last;
  129.         }
  130.         $pos = index($argumentative,$first);
  131.         if ($pos >= $[) {
  132.             if ($args[$pos+1] eq ':') {
  133.                 shift(@ARGV);
  134.                 if ($rest eq '') {
  135.                     unless (@ARGV) {
  136.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  137.                         ++$errs;
  138.                     }
  139.                     $rest = shift(@ARGV);
  140.                 }
  141.                 eval "\$opt_$first = \$rest;";
  142.             }
  143.             elsif ($args[$pos+1] eq '+') {
  144.                 shift(@ARGV);
  145.                 if ($rest eq '') {
  146.                     unless (@ARGV) {
  147.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  148.                         ++$errs;
  149.                     }
  150.                     $rest = shift(@ARGV);
  151.                 }
  152.                 eval "push(\@opt_$first, \$rest);";
  153.             }
  154.             else {
  155.                 eval "\$opt_$first = 1";
  156.                 if ($rest eq '') {
  157.                     shift(@ARGV);
  158.                 }
  159.                 else {
  160.                     $ARGV[0] = "-$rest";
  161.                 }
  162.             }
  163.         }
  164.         else {
  165.             print STDERR "apxs:Error: Unknown option: $first\n";
  166.             ++$errs;
  167.             if ($rest ne '') {
  168.                 $ARGV[0] = "-$rest";
  169.             }
  170.             else {
  171.                 shift(@ARGV);
  172.             }
  173.         }
  174.     }
  175.     return ($errs == 0, @ARGV);
  176. }
  177.  
  178. sub usage {
  179.     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
  180.     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
  181.     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
  182.     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
  183.     print STDERR "               [-Wl,<flags>] <files> ...\n";
  184.     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  185.     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  186.     exit(1);
  187. }
  188.  
  189. #   option handling
  190. my $rc;
  191. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
  192. &usage if ($rc == 0);
  193. &usage if ($#ARGV == -1 and not $opt_g);
  194. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
  195.  
  196. #   argument handling
  197. my @args = @ARGV;
  198. my $name = 'unknown';
  199. $name = $opt_n if ($opt_n ne '');
  200.  
  201. #   overriding of configuration variables
  202. if (@opt_S) {
  203.     my ($opt_S);
  204.     foreach $opt_S (@opt_S) {
  205.         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
  206.             my ($var, $val) = ($1, $2);
  207.             my $oldval = eval "\$CFG_$var";
  208.             unless ($var and $oldval) {
  209.                 print STDERR "apxs:Error: no config variable $var\n";
  210.                 &usage;
  211.             }
  212.             eval "\$CFG_${var}=\"${val}\"";
  213.         } else {
  214.             print STDERR "apxs:Error: malformatted -S option\n";
  215.             &usage;
  216.         }       
  217.     }
  218. }
  219.  
  220. ##
  221. ##  Initial DSO support check
  222. ##
  223. if (not -x "$CFG_SBINDIR/$CFG_TARGET") {
  224.     print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
  225.     exit(1);
  226. }
  227. if (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
  228.     print STDERR "apxs:Error: Sorry, no DSO support for Apache available\n";
  229.     print STDERR "apxs:Error: under your platform. Make sure the Apache\n";
  230.     print STDERR "apxs:Error: module mod_so is compiled into your server\n";
  231.     print STDERR "apxs:Error: binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
  232.     exit(1);
  233. }
  234.  
  235. ##
  236. ##  Operation
  237. ##
  238.  
  239. #   helper function for executing a list of
  240. #   system command with return code checks
  241. sub execute_cmds {
  242.     my (@cmds) = @_;
  243.     my ($cmd, $rc);
  244.  
  245.     foreach $cmd (@cmds) {
  246.         print STDERR "$cmd\n";
  247.         $rc = system("$cmd");
  248.         if ($rc != 0) {
  249.             printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc >> 8);
  250.             exit(1);
  251.         }
  252.     }
  253. }
  254.  
  255. if ($opt_g) {
  256.     ##
  257.     ##  SAMPLE MODULE SOURCE GENERATION
  258.     ##
  259.  
  260.     if (-d $name) {
  261.         print STDERR "apxs:Error: Directory `$name' already exists. Remove it first\n";
  262.         exit(1);
  263.     }
  264.  
  265.     my $data = join('', <DATA>);
  266.     $data =~ s|%NAME%|$name|sg;
  267.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  268.  
  269.     my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
  270.  
  271.     print STDERR "Creating [DIR]  $name\n";
  272.     system("mkdir $name");
  273.     print STDERR "Creating [FILE] $name/Makefile\n";
  274.     open(FP, ">${name}/Makefile") || die;
  275.     print FP $mkf;
  276.     close(FP);
  277.     print STDERR "Creating [FILE] $name/mod_$name.c\n";
  278.     open(FP, ">${name}/mod_${name}.c") || die;
  279.     print FP $src;
  280.     close(FP);
  281.  
  282.     exit(0);
  283. }
  284.  
  285. if ($opt_q) {
  286.     ##
  287.     ##  QUERY INFORMATION 
  288.     ##
  289.  
  290.     my $result = '';
  291.     my $arg;
  292.     foreach $arg (@args) {
  293.         my $ok = 0;
  294.         my $name;
  295.         foreach $name (qw(
  296.             TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  297.             PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
  298.         )) {
  299.             if ($arg eq $name or $arg eq lc($name)) {
  300.                 my $val = eval "\$CFG_$name";
  301.                 $result .= "${val}##";
  302.                 $ok = 1;
  303.             }
  304.         }
  305.         if (not $ok) {
  306.             printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
  307.             exit(1);
  308.         }
  309.     }
  310.     $result =~ s|##$||;
  311.     $result =~ s|##| |g;
  312.     print $result;
  313. }
  314.  
  315. if ($opt_c) {
  316.     ##
  317.     ##  DSO COMPILATION
  318.     ##
  319.  
  320.     #   split files into sources and objects
  321.     my @srcs = ();
  322.     my @objs = ();
  323.     my $f;
  324.     foreach $f (@args) {
  325.         if ($f =~ m|\.c$|) {
  326.             push(@srcs, $f);
  327.         }
  328.         else {
  329.             push(@objs, $f);
  330.         }
  331.     }
  332.  
  333.     #   determine output file
  334.     my $dso_file;
  335.     if ($opt_o eq '') {
  336.         if ($#srcs > -1) {
  337.             $dso_file = $srcs[0];
  338.             $dso_file =~ s|\.[^.]+$|.so|;
  339.         }
  340.         elsif ($#objs > -1) {
  341.             $dso_file = $objs[0];
  342.             $dso_file =~ s|\.[^.]+$|.so|;
  343.         }
  344.         else {
  345.             $dso_file = "mod_unknown.so";
  346.         }
  347.     }
  348.     else {
  349.         $dso_file = $opt_o;
  350.     }
  351.  
  352.     #   create compilation commands
  353.     my @cmds = ();
  354.     my $opt = '';
  355.     my ($opt_Wc, $opt_I, $opt_D);
  356.     foreach $opt_Wc (@opt_W) {
  357.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  358.     }
  359.     foreach $opt_I (@opt_I) {
  360.         $opt .= "-I$opt_I ";
  361.     }
  362.     foreach $opt_D (@opt_D) {
  363.         $opt .= "-D$opt_D ";
  364.     }
  365.     my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
  366.     my $s;
  367.     foreach $s (@srcs) {
  368.         my $o = $s;
  369.         $o =~ s|\.c$|.o|;
  370.         $o =~ s|^.*/||;
  371.         push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
  372.         unshift(@objs, $o);
  373.     }
  374.  
  375.     #   create link command
  376.     my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
  377.     my $o;
  378.     foreach $o (@objs) {
  379.         $cmd .= " $o";
  380.     }
  381.     $opt = '';
  382.     my ($opt_Wl, $opt_L, $opt_l);
  383.     foreach $opt_Wl (@opt_W) {
  384.         if ($CFG_LD_SHLIB !~ m/gcc$/) {
  385.             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  386.         } else {
  387.             $opt .= " -W$opt_Wl";
  388.         }
  389.     }
  390.     foreach $opt_L (@opt_L) {
  391.         $opt .= " -L$opt_L";
  392.     }
  393.     foreach $opt_l (@opt_l) {
  394.         $opt .= " -l$opt_l";
  395.     }
  396.     $cmd .= $opt;
  397.     $cmd .= " $CFG_LIBS_SHLIB";
  398.     push(@cmds, $cmd);
  399.  
  400.     #   execute the commands
  401.     &execute_cmds(@cmds);
  402.  
  403.     #   allow one-step compilation and installation
  404.     if ($opt_i or $opt_e) {
  405.         @args = ($dso_file);
  406.     }
  407. }
  408.  
  409. if ($opt_i or $opt_e) {
  410.     ##
  411.     ##  DSO INSTALLATION
  412.     ##
  413.  
  414.     #   determine installation commands
  415.     #   and corresponding LoadModule/AddModule directives
  416.     my @lmd = ();
  417.     my @amd = ();
  418.     my @cmds = ();
  419.     my $f;
  420.     foreach $f (@args) {
  421.         if ($f !~ m|\.so$|) {
  422.             print STDERR "apxs:Error: file $f is not a DSO\n";
  423.             exit(1);
  424.         }
  425.         my $t = $f;
  426.         $t =~ s|^.+/([^/]+)$|$1|;
  427.         if ($opt_i) {
  428.             push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
  429.             push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  430.         }
  431.  
  432.         #   determine module symbolname and filename
  433.         my $filename = '';
  434.         if ($name eq 'unknown') {
  435.             $name = '';
  436.             my $base = $f;
  437.             $base =~ s|\.[^.]+$||;
  438.             if (-f "$base.c") {
  439.                 open(FP, "<$base.c");
  440.                 my $content = join('', <FP>);
  441.                 close(FP);
  442.                 if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  443.                     $name = "$1";
  444.                     $filename = "$base.c";
  445.                     $filename =~ s|^[^/]+/||;
  446.                 }
  447.             }
  448.             if ($name eq '') {
  449.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  450.                     $name = "$1";
  451.                     $filename = $base;
  452.                     $filename =~ s|^[^/]+/||;
  453.                 }
  454.             }
  455.             if ($name eq '') {
  456.                 print STDERR "apxs:Error: Sorry, cannot determine bootstrap symbol name.\n";
  457.                 print STDERR "apxs:Error: Please specify one with option `-n'.\n";
  458.                 exit(1);
  459.             }
  460.         }
  461.         if ($filename eq '') {
  462.             $filename = "mod_${name}.c";
  463.         }
  464.         my $dir = $CFG_LIBEXECDIR;
  465.         $dir =~ s|^$CFG_PREFIX/?||;
  466.         $dir =~ s|(.)$|$1/|;
  467.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  468.         push(@amd, sprintf("AddModule %s", $filename));
  469.     }
  470.  
  471.     #   execute the commands
  472.     &execute_cmds(@cmds);
  473.  
  474.     #   activate module via LoadModule/AddModule directive
  475.     if ($opt_a or $opt_A) {
  476.         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
  477.             print STDERR "apxs:Error: Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found\n";
  478.             exit(1);
  479.         }
  480.  
  481.         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
  482.         my $content = join('', <FP>);
  483.         close(FP);
  484.  
  485.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  486.             print STDERR "apxs:Error: Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.\n";
  487.             print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
  488.             exit(1);
  489.         }
  490.  
  491.         my $lmd;
  492.         my $c = '';
  493.         $c = '#' if ($opt_A);
  494.         foreach $lmd (@lmd) {
  495.             my $what = $opt_A ? "preparing" : "activating";
  496.             if ($content !~ m|\n#?\s*$lmd|) {
  497.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  498.             } else {
  499.                  $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
  500.             }
  501.             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  502.             print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
  503.         }
  504.         my $amd;
  505.         foreach $amd (@amd) {
  506.             if ($content !~ m|\n#?\s*$amd|) {
  507.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  508.             } else {
  509.                  $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
  510.             }
  511.         }
  512.         if (@lmd or @amd) {
  513.             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
  514.                 print FP $content;
  515.                 close(FP);
  516.                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
  517.                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
  518.                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
  519.             } else {
  520.                 print STDERR "apxs:Error: unable to open configuration file\n";
  521.             }
  522.         }
  523.     }
  524. }
  525.  
  526. ##EOF##
  527. __DATA__
  528. ##
  529. ##  Makefile -- Build procedure for sample %NAME% Apache module
  530. ##  Autogenerated via ``apxs -n %NAME% -g''.
  531. ##
  532.  
  533. #   the used tools
  534. APXS=apxs
  535. APACHECTL=apachectl
  536.  
  537. #   additional user defines, includes and libraries
  538. #DEF=-Dmy_define=my_value
  539. #INC=-Imy/include/dir
  540. #LIB=-Lmy/lib/dir -lmylib
  541.  
  542. #   the default target
  543. all: mod_%NAME%.so
  544.  
  545. #   compile the DSO file
  546. mod_%NAME%.so: mod_%NAME%.c
  547.     $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
  548.  
  549. #   install the DSO file into the Apache installation
  550. #   and activate it in the Apache configuration
  551. install: all
  552.     $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
  553.  
  554. #   cleanup
  555. clean:
  556.     -rm -f mod_%NAME%.o mod_%NAME%.so
  557.  
  558. #   simple test
  559. test: reload
  560.     lynx -mime_header http://localhost/%NAME%
  561.  
  562. #   reload the module by installing and restarting Apache
  563. reload: install restart
  564.  
  565. #   the general Apache start/restart/stop procedures
  566. start:
  567.     $(APACHECTL) start
  568. restart:
  569.     $(APACHECTL) restart
  570. stop:
  571.     $(APACHECTL) stop
  572.  
  573. -=#=-
  574. /* 
  575. **  mod_%NAME%.c -- Apache sample %NAME% module
  576. **  [Autogenerated via ``apxs -n %NAME% -g'']
  577. **
  578. **  To play with this sample module, first compile it into a
  579. **  DSO file and install it into Apache's libexec directory 
  580. **  by running:
  581. **
  582. **    $ apxs -c -i mod_%NAME%.c
  583. **
  584. **  Then activate it in Apache's %TARGET%.conf file, for instance
  585. **  for the URL /%NAME%, as follows:
  586. **
  587. **    #   %TARGET%.conf
  588. **    LoadModule %NAME%_module libexec/mod_%NAME%.so
  589. **    <Location /%NAME%>
  590. **    SetHandler %NAME%
  591. **    </Location>
  592. **
  593. **  Then after restarting Apache via
  594. **
  595. **    $ apachectl restart
  596. **
  597. **  you immediately can request the URL /%NAME and watch for the
  598. **  output of this module. This can be achieved for instance via:
  599. **
  600. **    $ lynx -mime_header http://localhost/%NAME% 
  601. **
  602. **  The output should be similar to the following one:
  603. **
  604. **    HTTP/1.1 200 OK
  605. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  606. **    Server: Apache/1.3.4 (Unix)
  607. **    Connection: close
  608. **    Content-Type: text/html
  609. **  
  610. **    The sample page from mod_%NAME%.c
  611. */ 
  612.  
  613. #include "httpd.h"
  614. #include "http_config.h"
  615. #include "http_protocol.h"
  616. #include "ap_config.h"
  617.  
  618. /* The sample content handler */
  619. static int %NAME%_handler(request_rec *r)
  620. {
  621.     r->content_type = "text/html";      
  622.     ap_send_http_header(r);
  623.     if (!r->header_only)
  624.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  625.     return OK;
  626. }
  627.  
  628. /* Dispatch list of content handlers */
  629. static const handler_rec %NAME%_handlers[] = { 
  630.     { "%NAME%", %NAME%_handler }, 
  631.     { NULL, NULL }
  632. };
  633.  
  634. /* Dispatch list for API hooks */
  635. module MODULE_VAR_EXPORT %NAME%_module = {
  636.     STANDARD_MODULE_STUFF, 
  637.     NULL,                  /* module initializer                  */
  638.     NULL,                  /* create per-dir    config structures */
  639.     NULL,                  /* merge  per-dir    config structures */
  640.     NULL,                  /* create per-server config structures */
  641.     NULL,                  /* merge  per-server config structures */
  642.     NULL,                  /* table of config file commands       */
  643.     %NAME%_handlers,       /* [#8] MIME-typed-dispatched handlers */
  644.     NULL,                  /* [#1] URI to filename translation    */
  645.     NULL,                  /* [#4] validate user id from request  */
  646.     NULL,                  /* [#5] check if the user is ok _here_ */
  647.     NULL,                  /* [#3] check access by host address   */
  648.     NULL,                  /* [#6] determine MIME type            */
  649.     NULL,                  /* [#7] pre-run fixups                 */
  650.     NULL,                  /* [#9] log a transaction              */
  651.     NULL,                  /* [#2] header parser                  */
  652.     NULL,                  /* child_init                          */
  653.     NULL,                  /* child_exit                          */
  654.     NULL                   /* [#0] post read-request              */
  655. #ifdef EAPI
  656.    ,NULL,                  /* EAPI: add_module                    */
  657.     NULL,                  /* EAPI: remove_module                 */
  658.     NULL,                  /* EAPI: rewrite_command               */
  659.     NULL                   /* EAPI: new_connection                */
  660. #endif
  661. };
  662.  
  663.